// 刷新区列表
function listArea(gameId) {
	if(gameId != '' && gameId != null){
		$.ajax({
			type: "post",
			url: "/gameArea/select",
			data:{gameId:gameId},
			dataType:"json",
			async:false,
			success: function(data) {
				if(gameId == 1){
					$("#hideArea").show();
					$("#hideService").show();
				}else{
					$("#hideArea").hide();
					$("#hideService").hide();
				}
				$("#area_id").siblings().remove();
				for (var i=0;i<data.length;i++) {
					 html = '<option value="' +data[i].val+ '">'+ data[i].txt +'</option>';
					 $("#area_id").after(html);
				}
			}
		});
		
		$.ajax({
			type: "post",
			url: "/goodsType/select",
			data:{gameId:gameId},
			dataType:"json",
			async:false,
			success: function(data) {
				$("#goods_type").siblings().remove();
				for (var i=0;i<data.length;i++) {
					html = '<option value="' +data[i].val+ '">'+ data[i].txt +'</option>';
					$("#goods_type").after(html);
				}
			}
		});
	}else{
		$("#area_id").siblings().remove();
		$("#server_id").siblings().remove();
		$("#goods_type").siblings().remove();
	}
}

//下拉列表显示游戏服
function listServer(areaId) {
		if(areaId != '' && areaId != null){
			$.ajax({
				type: "post",
				url: "/gameServer/select",
				data:{gameId:$("#gameId").val(),areaId:areaId},
				dataType:"json",
				async:false,
				success: function(data) {
					$("#server_id").siblings().remove();
					for (var i=0;i<data.length;i++) {
						 html = '<option value="' +data[i].val+ '">'+ data[i].txt +'</option>';
						 $("#server_id").after(html);
					}
				}
			});
		}else{
			$("#server_id").siblings().remove();
		}
}

// 提交
function add(){
	if ($("#gameId").val() == null || $("#gameId").val() == '') {
		layer.msg("游戏不能为空!");
		return;
	}
	if ($("#gameId").val() == 1 && ($("#areaId").val() == null || $("#areaId").val() == '') ) {
		layer.msg("游戏区不能为空!");
		return;
	}
	console.log( $("#gameId").val()  );
	if ($("#gameId").val() == 1 && ($("#serverId").val() == null || $("#serverId").val() == '') ) {
		layer.msg("游戏服不能为空!");
		return;
	}
	if ($("#buyTotalNum").val() == null || $("#buyTotalNum").val() == '') {
		layer.msg("订单数量不能为空!");
		return;
	}
	var flag = /^[1-9]+/.test($("#buyTotalNum").val())? false:true ;
	if(flag){
		layer.msg("订单数量只能为正整数!");
		return;
	}
	if ($("#buyTotalNum").val() == null || $("#buyTotalNum").val() == '') {
		layer.msg("赠送URL/ID不能为空!");
		return;
	}
	if ($("#orderTotalMoney").val() == null || $("#orderTotalMoney").val() == '') {
		layer.msg("订单金额不能为空!");
		return;
	}
	console.log("game = " +$("#gameId").val() + " area = " + $("#areaId").val() + " server = " + $("#serverId").val());

	$("#addOrderForm").submit();

}